package com.xiaohai.wx.weather.test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;



public class LocationGenerator {
	
	public static void main(String[] args) throws IOException{
		
		//FileInputStream fis = new FileInputStream("d:\\tempLocation.txt");
		InputStream in = LocationGenerator.class.getClassLoader()
                .getResourceAsStream("tempLocation.txt");
        InputStreamReader isr = new InputStreamReader(in, "UTF-8");
        BufferedReader br = new BufferedReader(isr);
        String line = null;
        int i=0;
        String cityName;
        String cityCode;
        
        Map<String, String> cityNameCodeMap = new HashMap<String, String>();
        Map<String, String> countyNameCodeMap = new HashMap<String, String>();
        Map<String, String> districtNameCodeMap = new HashMap<String, String>();
        Map<String, String> qiNameCodeMap = new HashMap<String, String>();
        Map<String, String> otherNameCodeMap = new HashMap<String, String>();
        
        while ((line = br.readLine()) != null && i<50) {
            System.out.println(line);
            if(StringUtils.isNotBlank(line)){
            	cityName = line.substring(0, line.indexOf("="));
            	cityCode = line.substring(line.indexOf("=")+1, line.length());
            	String trimName = cityName;
            	if(cityName.length()> 2 && (cityName.endsWith("市") || cityName.endsWith("县") || cityName.endsWith("区") )){
            		trimName = cityName.substring(0, cityName.length()-1);
            	}
            	
            	if(cityName.endsWith("市")){
            		cityNameCodeMap.put(cityCode, trimName);
            	}else if(cityName.endsWith("县")){
            		countyNameCodeMap.put(cityCode, trimName);
            	}else if(cityName.endsWith("区")){
            		districtNameCodeMap.put(cityCode, trimName);
            	}else if(cityName.endsWith("旗")){
            		qiNameCodeMap.put(cityCode, trimName);
            	}else{
            		otherNameCodeMap.put(cityCode, trimName);
            	}	
            }
            i++;
        } 
        br.close();
        isr.close();
        in.close();
       
	}

}
